<template>
	<view class="tab">
		<scroll-view scroll-x class="tab-scroll">
			<view class="tab-scroll_box">
				<view class="tab-scroll_item" :class="{active:activeIndex === index}" v-for="(item,index) in list" :key="index" @click="tab(item,index)">
					{{item.name}}
				</view>
			</view>
		</scroll-view>
		<view class="tab_icons" @click="open">
			<uni-icons type="gear" size="26" color="#666"></uni-icons>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			list:{
				type:Array,
				require:true,
				default:()=>{
					return []
				}
			},
			tabIndex:{
				type:Number,
				require:true,
				default:() => {
					return 0
				}
			}
		},
		watch:{
			tabIndex(newVal,oldVal) {
				this.activeIndex = newVal
			}
		},
		data() {
			return {
				activeIndex:0
			};
		},
		methods:{
			tab(item,index){
				this.activeIndex = index;
				this.$emit('onTab',{
					data:item,
					index
				})
			},
			open(){
				uni.navigateTo({
					url:"/pages/home-label/home-label"
				})
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		display: flex;
		width: 100%;
		background-color: #fff;
		border-bottom: 1px #f5f5f5 solid;
		box-sizing: border-box;
        .tab-scroll{
			flex: 1;
			overflow: hidden;
			box-sizing: border-box;
		  .tab-scroll_box {
		  	display: flex;
		  	height: 45px;
		  	align-items: center;
		  	flex-wrap: nowrap;
		  	box-sizing: border-box;
		  
		  	// justify-content: center;
		  	.tab-scroll_item {
		  		flex-shrink: 0;
		  		padding: 0 10px;
		  		color: #333;
		  		font-size: 14px;
				&.active{
					color: $mk-base-color;
				}
		  	}
		  }	
		}
		.tab_icons{
			position: relative;
			width: 45px;
			display: flex;
			align-items: center;
			justify-content: center;
			&::after{
				position: absolute;
				content: '';
				width: 1px;
				top: 12px;
				bottom: 12px;
				left: 0;
				background-color: #ddd;
			}
		}
	}
</style>
